/*
 *店铺列表
 */
require(['jquery','../modules/pageSize','../modules/popup', 'jqScroller'],function($,pageSetSize,popup){
    //设置html根目录字体大小
    setRootFontSize(pageSetSize);
    var _ajaxManSend = false;
    var _shopManName = "";
    var curPagePos = 1;
    /*请求店铺列表*/
    jqScroller.render = function(cpage){
        popup.loadPopup("正在加载中...");
        $.ajax({
            type: "POST",
            url: "/Home/Member/ajaxChooseShop"+getFixedExtraUrl(),
            data: { "page" : cpage},
            dataType: "json",
            success: function (rs) {
                popup.removeLoad();
                if(rs && rs.data != null)  {
                    renderShopList(rs.data);
                    curPagePos++;
                    jqScroller.curPage++;
                    jqScroller.unblock();
                }else{
                    jqScroller.done();
                    if(curPagePos == 1){
                        $("#ajax-shop-list").html("<div class='no-data-txt'>没有数据！</div>");    
                    }else{                        
                        popup.alertPopup("没有更多数据！");
                    }                    
                }              
            },
            error: function () {
                popup.removeLoad();
                popup.alertPopup('服务器异常，请稍后重试！');
                jqScroller.unblock();
            }
        });
    };
    jqScroller.run();
    jqScroller.render(1);
    /*渲染店铺列表*/
    function renderShopList(list){
        var output = "";
        var c;
        for(var k in list){
            c = list[k];
            output += '<div class="one-info" onclick="goToShop('+c["local_id"]+')">';
            output += '<div class="row-h">';
            output += '<i class="sicon"></i><span class="stit">'+c["local_name"]+'</span><i class="arrow"></i>';
            output += '</div>';
            output += '<div class="row-b">';
            output += '<span class="dt">';
            output += '<i class="tit">'+c["current_bonus"]+'</i>';
            output += '<i class="mark">可用奖金</i>';
            output += '<i class="line"></i>';
            output += '</span>';
            output += '<span class="dt">';
            output += '<i class="tit">'+c["friend_num"]+'</i>';
            output += '<i class="mark">邀请朋友</i>';
            output += '<i class="line"></i>';
            output += '</span>';
            output += '<span class="dt">';
            output += '<i class="tit">'+c["wait_bonus"]+'</i>';
            output += '<i class="mark">即将收获</i>';
            output += '<i class="line"></i>';
            output += '</span>';
            output += '</div>';
            output += '</div>';
        }
        if(curPagePos % 10 == 0 || curPagePos == 1){
            $("#ajax-shop-list").html(output); 
        }else{
            $("#ajax-shop-list").append(output);
        }
    }    
    /*提交店铺人员真实姓名*/
    function ajaxShopManFill(){
        $.ajax({
            type: "POST",
            url: "/Home/Member/apimemberCoupon"+getFixedExtraUrl(),
            data: { "realname" : _shopManName},
            dataType: "json",
            success: function (rs) {
                _ajaxManSend = false;
                popup.removeLoad();
                popup.alertPopup(rs.msg);
                if(rs.status){
                    $(".pop-mask").remove();
                }
            },
            error: function () {
                _ajaxManSend = false;
                popup.removeLoad();
                popup.alertPopup('服务器异常，请稍后重试！');
            }
        });    
    }
    // popup.popup(".shopman-fill-dialog");
    $(".shopman-fill-dialog .sure-btn").on("click", function(){
        _shopManName = $("#tgr-name").val().trim();
        if(_shopManName == ""){
            popup.alertPopup('请填写您的真实姓名！');
        }
        if(_ajaxManSend) return;
        _ajaxManSend = true;
        ajaxShopManFill();
    });
});